package leetcode.view1711;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int findClosest(String[] words, String word1, String word2) {
		int i1 = -1, i2 = -1;
		int ans = 100002;
		for (int i = 0; i < words.length; i++) {
			String word = words[i];
			if (word.equals(word1)) {
				if (i2 != -1) {
					ans = Math.min(ans, i - i2);
				}
				i1 = i;
			} else if (word.equals(word2)) {
				if (i1 != -1) {
					ans = Math.min(ans, i - i1);
				}
				i2 = i;
			}
		}
		return ans;
	}

	@Override
	public void debug4() {
		H.compare(1, this.findClosest(H.str2array2("[\"I\",\"am\",\"a\",\"student\",\"from\",\"a\",\"university\",\"in\",\"a\",\"city\"]"), "a", "student"));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
